package com.liang.controller;

import com.liang.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {

    //名字一致
    @GetMapping("/t1")
    public String test1(String name, Model model){
        System.out.println("前端传递的数据为："+name);
        model.addAttribute("msg",name);
        return "test";
    }

    //名字不一致
    @GetMapping("/t2")
    public String test2(@RequestParam("name") String username, Model model){
        System.out.println("前端传递的数据为"+username);
        model.addAttribute("msg",username);
        return "test";
    }

    //传递的值为一个对象
    @GetMapping("/t3")
    public String test3(User user,Model model){
        System.out.println(user);
        model.addAttribute("msg",user);
        return "test";
    }

}
